<?php
defined('BY_JYA') or exit('error');
cfc('core')->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$return['set']=$this->plugin_setting('gusetting');
	$return['num']=pdo_count('jy_robshop_canlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'ispay'=>1));
	$return['money']=pdo_getsum('jy_robshop_canlog',array('ispay'=>1,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'fee');
	$member=pdo_get('jy_robshop_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	$item=model('core/member')->detail($_SESSION['uid'],array('nickname','avatar','realname','mobile','wechat'));
	$return['member']=array_merge($item,$member);
	$pluginset=$this->plugin_setting('setting');	
	$return['shop_action']=$pluginset['shop_action']?:'jy_robshop/index/';
	$return['info']=array(
		'realname'=>$item['realname'],
		'mobile'=>$item['mobile'],
		'wechat'=>$item['wechat'],
	);
	set_html('title','申请');
	exi($return);
	
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['realname']){
		exi('请填写姓名','error');
	}
	if(!$postdata['mobile']){
		exi('请填写手机号','error');
	}
	$updata=array(
		'ispartner'=>1,
		'realname'=>$postdata['realname'],
		'mobile'=>$postdata['mobile'],
		'wechat'=>$postdata['wechat']
	);
	$set=$this->plugin_setting('gusetting');
	if(!$set['become_check']){
		$updata['partnerstatus']=1;
		$updata['partnertime']=time();
	}
	pdo_update('jy_robshop_member',$updata,array('merchid'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(!$set['become_check']){
		exi('申请成功','','jy_robshop/gu.index/');
	}else{
		$pluginset=$this->plugin_setting('setting');	
		$shop_action=$pluginset['shop_action']?:'jy_robshop/index/';
		exi('已申请,请等待审核','',$shop_action);
	}
}
?>